package cn.cmkj.auction.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.cmkj.auction.R;
import cn.cmkj.auction.data.http.AuctionPrice;
import cn.cmkj.auction.widget.ptr.recyclerview.BaseRecycleAdapter;

/**
 * Created by cunguoyao on 2017/9/24.
 */

public class AuctionPriceListAdapter extends BaseRecycleAdapter {

    private Context context;
    private List<AuctionPrice> mData;

    public AuctionPriceListAdapter(Context context, List<AuctionPrice> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int onSpan(int position) {
        return 2;
    }

    @Override
    public int getItemCount() {
        int size = mData != null ? mData.size() : 0;
        return size;
    }

    public AuctionPrice getItem(int position) {
        if(mData == null || mData.size() <= 0)return null;
        AuctionPrice item = mData.get(position);
        return item;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext ()).inflate(R.layout.adapter_list_auction_price, parent, false);
        return new AuctionViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final AuctionPrice item = mData.get(position);
        if(item != null) {
            ((AuctionViewHolder) holder).paiPriceName.setText(item.getName());
            ((AuctionViewHolder) holder).paiPricePrice.setText("￥" + item.getPrice());
            ((AuctionViewHolder) holder).paiPriceState.setVisibility(View.GONE);
            ((AuctionViewHolder) holder).paiPriceTime.setText(item.getTime());
        }
    }

    class AuctionViewHolder extends RecyclerView.ViewHolder {
        public LinearLayout rootView;
        public TextView paiPriceName;
        public TextView paiPricePrice;
        public TextView paiPriceState;
        public TextView paiPriceTime;

        public AuctionViewHolder(View itemView) {
            super(itemView);
            this.rootView = (LinearLayout) itemView.findViewById(R.id.linear_layout);
            this.paiPriceName = (TextView) itemView.findViewById (R.id.pai_price_name);
            this.paiPricePrice = (TextView) itemView.findViewById (R.id.pai_price_price);
            this.paiPriceState = (TextView) itemView.findViewById (R.id.pai_price_state);
            this.paiPriceTime = (TextView) itemView.findViewById (R.id.pai_price_time);
        }
    }
}